package com.haha.dubbo.consumer.runner;

import com.haha.dubbo.consumer.api.service.DcCodeAPI;
import com.haha.dubbo.consumer.api.vo.DcCodeVO;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.dubbo.rpc.RpcContext;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

/**
 * @AUTHOR zhangxf
 * @CREATE 2020-03-10 17:46
 */
@Slf4j
@Component
public class DcCodeRunner implements ApplicationRunner {
    @Reference(interfaceClass = DcCodeAPI.class, loadbalance = "dcCode")
    private DcCodeAPI dcCodeAPI;
    @Override
    public void run(ApplicationArguments args) throws Exception {
        DcCodeVO dcCodeVO = new DcCodeVO();

        dcCodeVO.setDcCode("dcCode1");
        for (int i = 0; i < 40; i++) {
            dcCodeVO.setName("zxf" + i);
            RpcContext.getContext().setAttachment("dcCode", "dcCode2");
            dcCodeAPI.test(dcCodeVO);
        }
    }
}
